const express = require('express');
const router = express.Router();

/**
 * @param {Object} options
 * @param {} options.filter 编号或者名称
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forPartInvoiceManage/simple', async(req, res, next) => {
    const options = {
        filter: req.query.filter
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: 'id651',
                    code: 'code652',
                    name: 'name653',
                    shortName: 'shortName654',
                    countryName: 'countryName655',
                    contactPhone: 'contactPhone',
                    address: 'address',
                    kind: 1,
                    type: 1,
                    arrivedDealerCode: 'arrivedDealerCode656',
                    currency: 1,
                    seller: 'seller',
                    sellerAddress: 'sellerAddress',
                    sellerNumber: 'sellerNumber',
                    sellerFAX: 'sellerFAX'
                },
                {
                    id: 'id657',
                    code: 'code658',
                    name: 'name659',
                    shortName: 'shortName660',
                    countryName: 'countryName661',
                    contactPhone: 'contactPhone',
                    address: 'address',
                    kind: 1,
                    type: 1,
                    arrivedDealerCode: 'arrivedDealerCode662',
                    currency: 1,
                    seller: 'seller',
                    sellerAddress: 'sellerAddress',
                    sellerNumber: 'sellerNumber',
                    sellerFAX: 'sellerFAX'
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.code 编号
 * @param {} options.name 名称
 * @param {} options.shortCode 简编
 * @param {} options.shortName 简称
 * @param {} options.pageSize 每页数据量
 * @param {} options.pageIndex 指定页
 * @param {} options.sortField 排序字段
 * @param {} options.isDesc 倒序排列
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forPartInvoiceManage', async(req, res, next) => {
    const options = {
        code: req.query.code,
        name: req.query.name,
        shortCode: req.query.shortCode,
        shortName: req.query.shortName,
        pageSize: req.query.pageSize,
        pageIndex: req.query.pageIndex,
        sortField: req.query.sortField,
        isDesc: req.query.isDesc
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: 'id663',
                    code: 'code664',
                    name: 'name665',
                    shortName: 'shortName666',
                    countryName: 'countryName667',
                    contactPhone: 'contactPhone',
                    address: 'address',
                    kind: 1,
                    type: 1,
                    arrivedDealerCode: 'arrivedDealerCode668',
                    currency: 1,
                    seller: 'seller',
                    sellerAddress: 'sellerAddress',
                    sellerNumber: 'sellerNumber',
                    sellerFAX: 'sellerFAX'
                },
                {
                    id: 'id669',
                    code: 'code670',
                    name: 'name671',
                    shortName: 'shortName672',
                    countryName: 'countryName673',
                    contactPhone: 'contactPhone',
                    address: 'address',
                    kind: 1,
                    type: 1,
                    arrivedDealerCode: 'arrivedDealerCode674',
                    currency: 1,
                    seller: 'seller',
                    sellerAddress: 'sellerAddress',
                    sellerNumber: 'sellerNumber',
                    sellerFAX: 'sellerFAX'
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});
router.get('/', (req, res) => {
    const content = [];
    for(let i = 0; i < 5; i++) content.push({
        id: `${i + 1}`,
        code: `201900${i}`,
        name: `上海${i}`,
        shortCode: 'string',
        shortName: 'string',
        kind: 20,
        marketDepartmentCode: 'string',
        country: 'string',
        province: 'string',
        city: 'string',
        county: 'string',
        contactNumber: 'string',
        address: 'string',
        options: [
            'update'
        ]
    });
    res.json({
        message: '',
        payload: {
            content,
            totalElements: 5,
        }
    });
});

router.put('/:id', (req, res) => {
    res.json({
        message: '编辑成功'
    });
});

const data = [];
for(let i = 1; i < 51; i++)
    data.push({
        id: `${i}`,
        code: `dealerCode${i}`,
        name: `dealerName${i}`,
        branchCode: `branchCode${i}`,
        provinceName: `provinceName${i}`,
        cityName: `cityName${i}`,
        countyName: `countyName${i}`,
        contactName: `contactName${i}`,
        contactPhone: `contactPhone${i}`,
        address: `address${i}`,
        currency: 1,
    });

router.get('/forSubDealer/simple', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            content: data.slice(0, 10),
        }
    });
});

router.get('/forSubDealer', (req, res) => {
    const dealers = [];
    for(let i = 0; i < 40; i++)
        dealers.push({
            id: `${i}`,
            code: `subDealer${i}`,
            name: `name${i}`,
            shortCode: `shortCode${i}`,
            shortName: `shortName${i}`,
            countryName: '中国',
            provinceName: `湖北省${i}`,
            cityName: `cityName${i}`,
            address: `address${i}`,
        });
    res.json({
        message: 'ok',
        payload: {
            content: dealers,
            totalElements: dealers.length,
        }
    });
});
router.get('/forPartSaleOrder/simple', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            content: data.slice(0, 10),
        }
    });
});

router.get('/forPartSaleOrder', (req, res) => {
    const dealers = [];
    for(let i = 0; i < 40; i++)
        dealers.push({
            id: `${i}`,
            code: `subDealer${i}`,
            name: `name${i}`,
            shortCode: `shortCode${i}`,
            shortName: `shortName${i}`,
            countryName: '中国',
            provinceName: `湖北省${i}`,
            cityName: `cityName${i}`,
            address: `address${i}`,
            currency: 1,
        });
    res.json({
        message: 'ok',
        payload: {
            content: dealers,
            totalElements: dealers.length,
        }
    });
});


router.get('/forCurrentUser', (req, res) => {
    const content = [];
    for(let i = 0; i < 40; i++) content.push({
        id: `id${i}`,
        code: `code${i}`,
        name: `name${i}`,
        shortCode: 'shortCode',
        shortName: 'shortName',
        country: 'country',
        province: 'province',
        city: 'city',
        contactNumber: 'contactNumber',
        address: 'address',
        kind: 21,
        options: [
            'update'
        ]
    });

    res.json({
        message: 'ok',
        payload: {
            content,
            totalElements: 40,
        }
    });
});

const parts = [];
for(let i = 0; i < 40; i++)
    parts.push({
        partId: `partid${i}`,
        partCode: `partCode${i}`,
        partName: `partName${i}`
    });

router.get('/:id/forDealerPartInformation', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            id: 'id1',
            code: 'code1',
            name: 'name1',
            shortCode: 'shortCode',
            shortName: 'shortName',
            country: 'country',
            province: 'province',
            city: 'city',
            contactNumber: 'contactNumber',
            address: 'address',
            fax: 'fax',
            kind: 21,
            zipCode: 'zipCode',
            rowVersion: 'rowVersion',
            options: [
                'update'
            ],
            dealerParts: [{
                id: '9689a787',
                brandId: 'de872f12',
                brandCode: 'brandCode',
                brandName: 'brandName',
                tradeMethodId: '52a1ad34',
                tradeMethodCode: '2020',
                tradeMethodName: '奇瑞汽车股份有限公司配件分公司',
                arrivedDealerId: 'arrivedDealerId',
                arrivedDealerCode: 'arrivedDealerCode',
                arrivedDealerName: 'arrivedDealerName',
                priceClause: 1,
                isSeparate: true,
                isPlaned: true,
                currency: 2,
                labelRequirement: 'labelRequirement',
                palletizing: 1,
                shippingMark: 'shippingMark',
                isClaim: true,
                mgmtRate: 0.5,
                remark: 'testremark'
            }],
            dealerBanks: [{
                bankId: 'bankId',
                bankCode: 'bankCode',
                bankName: 'bankName'
            }, {
                bankId: 'bankId2',
                bankCode: 'bankCode2',
                bankName: 'bankName2'
            }],
            parts,
            orderingCalendars: [{
                partSaleOrderTypeId: 'string',
                partSaleOrderTypeCode: '正常订单',
                partSaleOrderTypeName: '正常订单',
                calendar: [{
                    year: 2019,
                    month: 8,
                    day: 25
                }, {
                    year: 2019,
                    month: 8,
                    day: 26
                }]
            }, {
                partSaleOrderTypeId: 'partSaleOrderTypeId',
                partSaleOrderTypeCode: '紧急订单',
                partSaleOrderTypeName: '紧急订单',
                calendar: [{
                    year: 2019,
                    month: 9,
                    day: 27
                }, {
                    year: 2019,
                    month: 7,
                    day: 28
                }]
            }]
        }
    });
});

router.put('/:id/forDealerPartInformation', (req, res) => {
    res.json({
        message: '成功',
    });
});

router.get('/forPersonnel', (req, res) => {
    const content = [];
    for(let i = 0; i < 40; i++) content.push({
        id: `id${i}`,
        code: `code${i}`,
        name: `name${i}`,
        shortName: 'shortName',
        kind: 21,
        type: 1,
        country: 'country',
        contactNumber: 'contactNumber',
        address: 'address'
    });

    res.json({
        message: 'ok',
        payload: {
            content,
            totalElements: 40,
        }
    });
});

router.get('/forPersonnel/simple', (req, res) => {
    const content = [];
    for(let i = 0; i < 10; i++) content.push({
        id: `id${i}`,
        code: `code${i}`,
        name: `name${i}`,
        shortName: 'shortName',
        kind: 20,
        type: 1,
        country: 'country',
        contactNumber: 'contactNumber',
        address: 'address'
    });

    res.json({
        message: 'ok',
        payload: {
            content,
            totalElements: 10,
        }
    });
});

router.get('/:id', (req, res) => {
    res.json(
        {
            message: 'string',
            payload: {
                id: '1',
                code: 'string',
                name: 'string',
                shortCode: 'string',
                shortName: 'string',
                kind: 20,
                areaId: '1',
                areaName: '东亚',
                countryId: '1',
                countryName: '中国',
                provinceId: '3',
                provinceName: '江西省',
                cityId: '5',
                cityName: '宜春市',
                contactNumber: 'string',
                fax: 'string',
                email: 'string',
                address: 'string',
                zipCode: 'string',
                juridicalPerson: 'string',
                juridicalPersonPhone: 'string',
                juridicalPersonEmail: 'string',
                generalManager: 'string',
                generalManagerPhone: 'string',
                generalManagerEmail: 'string',
                salesDirector: 'string',
                salesDirectorPhone: 'string',
                salesDirectorEmail: 'string',
                serviceDirector: 'string',
                serviceDirectorPhone: 'string',
                serviceDirectorEmail: 'string',
                marketDirector: 'string',
                marketDirectorPhone: 'string',
                marketDirectorEmail: 'string',
                financialController: 'string',
                financialControllerPhone: 'string',
                financialControllerEmail: 'string',
                salesInterfacePerson: 'string',
                salesInterfacePhone: 'string',
                salesInterfaceEmail: 'string',
                serviceInterfacePerson: 'string',
                serviceInterfacePhone: 'string',
                serviceInterfaceEmail: 'string',
                incorporatedDate: '2019-08-26T02:42:15.054Z',
                startTime: '2019-08-26T02:42:15.054Z',
                authorisedMethod: 1,
                authorisedArea: 'string',
                arrivedAddress: 'string',
                openDate: '2019-08-26T02:42:15.054Z',
                onlineStatus: 1,
                updatedDate: '2019-08-26T02:42:15.054Z',
                dealers: [{
                    id: 'string',
                    code: 'string',
                    name: 'string',
                    shortCode: 'string',
                    shortName: 'string',
                    countryName: 'string',
                    provinceName: 'string',
                    cityName: 'string',
                    address: 'string'
                }],
                personnels: [{
                    id: 'string',
                    userName: 'string',
                    name: 'string',
                }],
                options: [
                    'update'
                ]
            }
        }
    );
});
router.post('/forNoticeImport', (req, res) => {
    const data = [];
    for(let i = 1; i < 51; i++)
        data.push({
            id: `${i}`,
            code: `dealerCode${i}`,
            name: `dealerName${i}`,
        });
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: data,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});
module.exports = router;
